<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/**
 * 
 * @filesource admin_tree.php
 */
if (0) {
    ?><script><?php } ?>

    Ext.define('Hydcrm.AdminTree', {
        extend: 'Ext.tree.Panel',
        initComponent: function () {
            var me = this;
            Ext.apply(this, {
                margin: 2,
                region: 'west',
                title: '系统菜单',
                id: 'west-pannel',
                //collapsible :true,
                width: 230,
                //useArrows : true,// 树的展开和收缩样式
                lines: true, //节点之间连接的横竖线 
                store: this.getTreeStore(),
                rootVisible: false,
                folderSort: true,
                singleExpand: false,
                dockedItems: [{
                        xtype: 'toolbar',
                        dock: 'top',
                        items: [{
                                id: 'expandAll',
                                iconCls: 'icon-expand',
                                text: '全部展开',
                                hidden: true,
                                handler: function () {
                                    me.expandAll();
                                    Ext.getCmp("expandAll").hide();
                                    Ext.getCmp("collapseAll").setVisible(true);
                                }
                            }, {
                                id: 'collapseAll',
                                iconCls: 'icon-collapse',
                                text: '全部闭合',
                                handler: function () {
                                    me.collapseAll();
                                    Ext.getCmp("collapseAll").hide();
                                    Ext.getCmp("expandAll").setVisible(true);
                                }
                            }, '->', {
                                iconCls: 'icon-refresh',
                                text: '刷新',
                                onClick: function () {
                                    me.getStore().on('beforeload', function () {
                                        me.el.mask('loadingText', 'x-mask-loading');
                                    });
                                    me.getStore().load({
                                        callback: function () {
                                            me.el.unmask();
                                        }
                                    });
                                }
                            }]
                    }, {
                        xtype: 'toolbar',
                        dock: 'bottom',
                        items: [{
                                text: '版本',
                                iconCls: 'icon-info',
                                onClick: function () {
                                    //
                                }
                            },{
                                text: '修改密码',
                                iconCls: 'icon-pass',
                                handler: function () {
                                    if(!Ext.getCmp('user_pass_window')){
                                        new Hydcrm.user.UserPassWindow().show();
                                    }
                                }
                            },{
                                text: '退出',
                                iconCls: 'icon-logout',
                                href: '<?php echo BASEURL; ?>index.php/login/loginout',
                                hrefTarget: '_self',
                                handler: function () {
                                    //me.expandAll();
                                }
                            }]
                    }]
            });

            this.callParent(arguments);

            me.on('itemclick', function (m, rec) {	
                if(rec.get('leaf')===true){ //alert(rec.get('tag')+'_tab'); 
                    var admin_center_panel = Ext.getCmp('admin_center_panel');  
                    if(rec.get('tag')==='user_info'){//员工信息维护
                        if(!Ext.getCmp('user_info_tab')){ //var usergrid = Ext.create("Hydcrm.user.UserGrid",{title:'****'});   alert(rec.get('tag'));
                            var usergrid =  new Hydcrm.user.UserGrid();
                            admin_center_panel.add(usergrid);
                        }
                        admin_center_panel.setActiveTab("user_info_tab");
                    }else if(rec.get('tag')==='user_quit'){//离职管理
                        if(!Ext.getCmp('user_quit_tab')){
                            var userquitgrid = new Hydcrm.user.UserQuitGrid({title:'离职管理'});
                            admin_center_panel.add(userquitgrid);
                        }
                        admin_center_panel.setActiveTab("user_quit_tab");
                    }else if(rec.get('tag')==='user_pinfo'){//个人信息维护
                        if(!Ext.getCmp('user_pinfo_window')){
                            new Hydcrm.user.UserPinfoWindow().show();
                        }
                    }else if(rec.get('tag')==='team_info'){//团队维护
                        if(!Ext.getCmp('team_info_tab')){
                            var teamgridform = new Hydcrm.team.TeamGridForm({title:'团队维护'});
                            admin_center_panel.add(teamgridform);
                        }
                        admin_center_panel.setActiveTab("team_info_tab");
                    }else if(rec.get('tag')==='department'){//部门管理
                        if(!Ext.getCmp('department_tab')){
                            var departmentgridform = new Hydcrm.department.DepartmentGridForm({title:'部门管理'});
                            admin_center_panel.add(departmentgridform);
                        }
                        admin_center_panel.setActiveTab("department_tab");
                    }else if(rec.get('tag')==='position'){//岗位管理
                        if(!Ext.getCmp('position_tab')){
                            var positiongridform = new Hydcrm.position.PositionGridForm({title:'岗位管理'});
                            admin_center_panel.add(positiongridform);
                        }
                        admin_center_panel.setActiveTab("position_tab");
                    }
                }

            });
        },
        getTreeStore: function () {
            return Ext.create('Ext.data.TreeStore', {
                fields: ['id', 'tag', 'nodetype', 'text'],
                proxy: {
                    type: 'ajax',
                    url: Hydcrm.CONF.CONN_URL,
                    extraParams: {
                        module: 'module',
                        action: 'get_module_tree'
                    },
                    actionMethods: {
                        read: 'POST'
                    }
                },
                sorters: [{
                        property: 'id',
                        direction: 'ASC'
                    }],
                autoLoad: true
            });
        }

    });

    /* End of file admin_tree.php */